﻿using System.Collections.Generic;
using Managistics.Model;
using Managistics.Warehouse.Configuration;
using Managistics.Warehouse.Controllers.Interfaces;
using Managistics.Warehouse.Views.Interfaces;
using Managistics.Warehouse.Factories;
using Managistics.Core.Services;
using Managistics.Utility;
using Managistics.Utility.Common;

namespace Managistics.Warehouse.Controllers
{
    public class SubController : ISubController
    {
        private readonly IInventoryService inventoryService;
        private readonly IPurchaseReportService purchaseReportService;
        private readonly IBasicService basicService;

        readonly ISubView subView;
        readonly ComplexParameterObject parameter;

        public SubController(ISubView subView, ComplexParameterObject parameter,
            IInventoryService inventoryService, IPurchaseReportService purchaseReportService,
            IBasicService basicService)
        {
            this.subView = subView;
            this.parameter = parameter;
            this.inventoryService = inventoryService;
            this.purchaseReportService = purchaseReportService;
            this.basicService = basicService;

            subView.ClickGetParameterButtonClicked += SetText;
            subView.ClickImportRelationsButtonClicked += ExecuteImportRelations;

            subView.ClickExportPurchaseOrderDetailButtonClicked += ExportPurchaseOrderDetail;
            subView.ClickExportPurchaseInputDetailButtonClicked += ExportPurchaseInputDetail;
            subView.ClickExportPurchaseBacklogDetailButtonClicked += ExportPurchaseBacklogDetail;
            subView.ClickExportPurchaseNonInputDetailButtonClicked += ExportPurchaseNonInputDetail;


            subView.ClickTestFuncRepoClicked += ClickTestFuncRepo;

            subView.ClickExecuteAdjustClicked += ClickExecuteAdjust;
        }

        public void Run()
        {
            subView.Open();
        }

        public void Stop(string key) { }

        void SetText()
        {
            // parameter PurchaseOrder tu view day
            subView.SetText(parameter.Text);
        }

        void ExecuteImportRelations()
        {
            inventoryService.ImportToCreateRelations(string.Empty, 5);
        }

        public void ExportPurchaseOrderDetail()
        {
            purchaseReportService.GetPurchaseOrderedDetail(new PurchaseReportsVO
            {
                ReportBy = 1, // report by Good
                StartDate = DateTimeWithZone.string2DateTime("01/08/2012"),
                EndDate = DateTimeWithZone.string2DateTime("31/08/2012"),
                GoodCode = string.Empty,
                SupplierCode = string.Empty,
                InputType = 0
            });
            // Supplier
            purchaseReportService.GetPurchaseOrderedDetail(new PurchaseReportsVO
            {
                ReportBy = 2, // report by Supplier
                StartDate = DateTimeWithZone.string2DateTime("01/08/2012"),
                EndDate = DateTimeWithZone.string2DateTime("31/08/2012"),
                GoodCode = string.Empty,
                SupplierCode = string.Empty,
                InputType = 0
            });
        }

        public void ExportPurchaseInputDetail()
        {
            purchaseReportService.GetPurchaseInputedDetail(new PurchaseReportsVO
            {
                ReportBy = 1, // report by Good
                StartDate = DateTimeWithZone.string2DateTime("01/08/2012"),
                EndDate = DateTimeWithZone.string2DateTime("31/08/2012"),
                GoodCode = string.Empty,
                SupplierCode = string.Empty,
                InputType = 0
            });
            purchaseReportService.GetPurchaseInputedDetail(new PurchaseReportsVO
            {
                ReportBy = 2, // report by Supplier
                StartDate = DateTimeWithZone.string2DateTime("01/08/2012"),
                EndDate = DateTimeWithZone.string2DateTime("31/08/2012"),
                GoodCode = string.Empty,
                SupplierCode = string.Empty,
                InputType = 0
            });
        }

        public void ExportPurchaseBacklogDetail()
        {
            purchaseReportService.GetPurchaseBacklogDetail(new PurchaseReportsVO
            {
                ReportBy = 1, // report by Good
                StartDate = DateTimeWithZone.string2DateTime("01/08/2011"),
                EndDate = DateTimeWithZone.string2DateTime("31/08/2011"),
                GoodCode = string.Empty,
                SupplierCode = string.Empty,
                InputType = 0
            });
            purchaseReportService.GetPurchaseBacklogDetail(new PurchaseReportsVO
            {
                ReportBy = 2, // report by Supplier
                StartDate = DateTimeWithZone.string2DateTime("01/08/2011"),
                EndDate = DateTimeWithZone.string2DateTime("31/08/2011"),
                GoodCode = string.Empty,
                SupplierCode = string.Empty,
                InputType = 0
            });
        }

        public void ExportPurchaseNonInputDetail()
        {
            purchaseReportService.GetPurchaseNonInputDetail(new PurchaseReportsVO
            {
                ReportBy = 1, // report by Good
                StartDate = DateTimeWithZone.string2DateTime("01/08/2013"),
                EndDate = DateTimeWithZone.string2DateTime("31/08/2013"),
                GoodCode = string.Empty,
                SupplierCode = string.Empty,
                InputType = 0
            });
            purchaseReportService.GetPurchaseNonInputDetail(new PurchaseReportsVO
            {
                ReportBy = 2, // report by Good
                StartDate = DateTimeWithZone.string2DateTime("01/08/2013"),
                EndDate = DateTimeWithZone.string2DateTime("31/08/2013"),
                GoodCode = string.Empty,
                SupplierCode = string.Empty,
                InputType = 0
            });
        }


        public void ClickTestFuncRepo()
        {
            //basicService.Testing();

            //inventoryService.GetParityGoods2AdjustInMonth(new AdjustParityRetailVO
            //{
            //    GoodCode = string.Empty,
            //    GoodName = string.Empty,
            //    AdjustMonth = 8,
            //    AdjustYear = 2013
            //});
        }

        public void ClickExecuteAdjust()
        {
            inventoryService.ExecuteAdjustInMonth(new AdjustParityRetailVO
            {
                GoodCode = string.Empty,
                GoodName = string.Empty,
                AdjustMonth = 8,
                AdjustYear = 2013
            });
        }
    }
}